home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / ICMPDUMP.C < prev    next >
Text File  |  1993-10-14  |  2KB  |  68 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "netuser.h"
  6. #include "icmp.h"
  7. #include "trace.h"
  8. #include "ip.h"
  9.  
  10. /* Dump an ICMP header */
  11. void
  12. icmp_dump(FILE *fp,struct mbuf **bpp,int32 source,int32 dest,int check)
  13. {
  14.     struct icmp icmp;
  15.     int16 csum = 0;
  16.  
  17.     if(bpp == NULLBUFP || *bpp == NULLBUF) {
  18.         return;
  19.     }
  20.     if(check) {
  21.         csum = cksum(NULLHEADER,*bpp,len_p(*bpp));
  22.     }
  23.     ntohicmp(&icmp,bpp);
  24.  
  25.     trprintf(fp,"ICMP: type %s",Icmptypes[uchar(icmp.type)]);
  26.  
  27.     switch(uchar(icmp.type)){
  28.     case ICMP_DEST_UNREACH:
  29.         trprintf(fp," code %s",Unreach[uchar(icmp.code)]);
  30.         break;
  31.     case ICMP_REDIRECT:
  32.         trprintf(fp," code %s",Redirect[uchar(icmp.code)]);
  33.         trprintf(fp," new gateway %s",inet_ntoa(icmp.args.address));
  34.         break;
  35.     case ICMP_TIME_EXCEED:
  36.         trprintf(fp," code %s",Exceed[uchar(icmp.code)]);
  37.         break;
  38.     case ICMP_PARAM_PROB:
  39.         trprintf(fp," pointer %u",icmp.args.pointer);
  40.         break;
  41.     case ICMP_ECHO:
  42.     case ICMP_ECHO_REPLY:
  43.     case ICMP_INFO_RQST:
  44.     case ICMP_INFO_REPLY:
  45.     case ICMP_TIMESTAMP:
  46.     case ICMP_TIME_REPLY:
  47.         trprintf(fp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  48.         pullup(bpp,NULLCHAR,sizeof(int32));
  49.         break;
  50.     }
  51.     if(csum) {
  52.         trprintf(fp," CHECKSUM ERROR (%u)",csum);
  53.     }
  54.     trprintf(fp,"\n");
  55.  
  56.     /* Dump the offending IP header, if any */
  57.     switch(icmp.type){
  58.     case ICMP_DEST_UNREACH:
  59.     case ICMP_TIME_EXCEED:
  60.     case ICMP_PARAM_PROB:
  61.     case ICMP_QUENCH:
  62.     case ICMP_REDIRECT:
  63.         trprintf(fp,"Returned ");
  64.         ip_dump(fp,bpp,0);
  65.     }
  66. }
  67.  
  68.